package com.haima.ziliao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haima.common.annotation.RepeatSubmit;
import com.haima.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haima.common.annotation.Log;
import com.haima.common.core.controller.BaseController;
import com.haima.common.core.domain.AjaxResult;
import com.haima.common.enums.BusinessType;
import com.haima.ziliao.domain.PMyaddr;
import com.haima.ziliao.service.IPMyaddrService;
import com.haima.common.utils.poi.ExcelUtil;
import com.haima.common.core.page.TableDataInfo;

/**
 * 收件地址Controller
 * 
 * @author hima
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/ziliao/myaddr")
public class PMyaddrController extends BaseController
{
    @Autowired
    private IPMyaddrService pMyaddrService;

    /**
     * 查询收件地址列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:list')")
    @GetMapping("/list")
    public TableDataInfo list(PMyaddr pMyaddr)
    {
        startPage();
        List<PMyaddr> list = pMyaddrService.selectPMyaddrList(pMyaddr);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(PMyaddr pMyaddr)
    {
        pMyaddr.setUid(SecurityUtils.getUserId());
        List<PMyaddr> list = pMyaddrService.selectPMyaddrList(pMyaddr);
        return AjaxResult.success(list);
    }

    @GetMapping("/editData")
    @RepeatSubmit
    public AjaxResult editData(PMyaddr pMyaddr)
    {
        PMyaddr nadd = pMyaddrService.selectPMyaddrById(pMyaddr.getId());
        nadd.setName(pMyaddr.getName());
        nadd.setAddr(pMyaddr.getAddr());
        nadd.setPhone(pMyaddr.getPhone());
        pMyaddrService.updatePMyaddr(nadd);
        return AjaxResult.success();
    }

    @GetMapping("/addData")
    @RepeatSubmit
    public AjaxResult addData(PMyaddr pMyaddr)
    {
        pMyaddr.setUid(SecurityUtils.getUserId());
        pMyaddrService.insertPMyaddr(pMyaddr);
        return AjaxResult.success();
    }
    @GetMapping("/shanchu")
    @RepeatSubmit
    public AjaxResult shanchu(PMyaddr pMyaddr)
    {
        pMyaddrService.deletePMyaddrById(pMyaddr.getId());
        return AjaxResult.success();
    }

    /**
     * 导出收件地址列表
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:export')")
    @Log(title = "收件地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PMyaddr pMyaddr)
    {
        List<PMyaddr> list = pMyaddrService.selectPMyaddrList(pMyaddr);
        ExcelUtil<PMyaddr> util = new ExcelUtil<PMyaddr>(PMyaddr.class);
        util.exportExcel(response, list, "收件地址数据");
    }

    /**
     * 获取收件地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pMyaddrService.selectPMyaddrById(id));
    }

    /**
     * 新增收件地址
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:add')")
    @Log(title = "收件地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PMyaddr pMyaddr)
    {
        return toAjax(pMyaddrService.insertPMyaddr(pMyaddr));
    }

    /**
     * 修改收件地址
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:edit')")
    @Log(title = "收件地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PMyaddr pMyaddr)
    {
        return toAjax(pMyaddrService.updatePMyaddr(pMyaddr));
    }

    /**
     * 删除收件地址
     */
    @PreAuthorize("@ss.hasPermi('ziliao:myaddr:remove')")
    @Log(title = "收件地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pMyaddrService.deletePMyaddrByIds(ids));
    }
}
